Skip to content

Android SDK build scripts #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

marcprux
Copy link

Following up on swiftlang/github-workflows#106 and swiftlang/swift#80788, this PR contains a new swift-docker/swift-ci/sdks/android/ folder with scripts that will build and upload a full stand-alone Swift Android Swift SDK. It is modeled after the structure of the swift-ci/sdks/static-linux build scripts.

Running

The top-level ./build script installs a host toolchain and the Android NDK, and then invokes scripts/fetch-source.sh which will fetch tagged sources for libxml2, curl, boringssl, and swift.

It then applies some patches and invokes scripts/build.sh, which will build the sources for each of the specified architectures. Finally, it combines the NDK and the newly built SDKs into a single artifactbundle.

Specifying Architectures

By default all the supported Android architectures (aarch64, x86_64, aarmv7) will be built, but this can be reduced in order to speed up the build. This can be useful, e.g., as part of a CI that validates a pull request, as building a single architecture takes around 30 minutes on a standard ubuntu-24.04 GitHub runner, whereas building for all the architectures takes over an hour.

To build an artifactbundle for just the x86_64 architecture, run:

TARGET_ARCHS=x86_64 ./build

Installing and validating the SDK

The .github/workflows/pull_request.yml workflow will create and upload an installable SDK named something like: swift-6.1-RELEASE_android-0.1.artifactbundle.tar.gz. The results of one of the workflow runs can be seen at https://github.com/swift-android-sdk/swift-docker/actions/runs/14603885089

The workflow will also install the SDK locally and use swift-android-action to build and test various Swift packages in an Android emulator.

marcprux and others added 5 commits March 31, 2025 14:28
* Build Android image

* Checkout without ssh

* Retry build if it fails

* Swift 6.1 Release Dockerfiles (swiftlang#456)

* Change binutils-gold package dependency on Debian 12 to binutils (swiftlang#457)

* Update installed packages after nightly platform expansion (swiftlang#458)

* update nightly-6.1 dependencies

* update nightly-main dependencies

* fix ubuntu images

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Fedora 41 Dockerfile (swiftlang#464)

* Build Android image

* Build Android image

* Swift 6.1 Release Dockerfiles (swiftlang#456)

* Change binutils-gold package dependency on Debian 12 to binutils (swiftlang#457)

* Build Android image

* Build Android image

* Build Android image

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Android SDK build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Androd build

* Swift Android build

* Swift Android build

* Swift Android build

* Swift Android build

---------

Co-authored-by: Mishal Shah <[email protected]>
Co-authored-by: Chris McGee <[email protected]>
Co-authored-by: Justice Adams <[email protected]>
Co-authored-by: Andrew Sukach <[email protected]>
* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Start splitting NDK out from the rest of the SDK

* Start splitting NDK out from the rest of the SDK

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2

* Swift Android build 6.2
* Swift Android build 6.2

* Swift Android build 6.2

* Add post-install script to SDK bundle

* Add post-install script to SDK bundle

* Add post-install script to SDK bundle

* Add post-install script to SDK bundle
@marcprux
Copy link
Author

marcprux commented May 8, 2025

I've updated this PR to build the SDK without including the Android NDK. In order to accommodate this, there is now a post-install scripts/setup-android-sdk.sh that will need to be run manually after the swift sdk install … command. This will find the NDK based on the standard ANDROID_NDK_HOME environment variable and create links from the NDK into the path specified by swift-sdk.json's sdkRootPath, as well as pulling in the swiftrt.o to work around swiftlang/swift#79621.

The latest result of the build for the 6.2 nightly can be seen at: https://github.com/skiptools/swift-android-toolchain/releases/tag/6.2-DEVELOPMENT-SNAPSHOT-2025-05-07-a

@marcprux marcprux marked this pull request as ready for review May 8, 2025 19:30
@marcprux marcprux requested a review from shahmishal as a code owner May 8, 2025 19:30
@marcprux
Copy link
Author

marcprux commented May 8, 2025

To clarify what the post-install script is doing, following is a result of the output of the command with the default NDK directory:

zap org.swift.swiftpm/swift-sdks % tree swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-07-a-android-0.1.artifactbundle/swift-android/ndk-sysroot
└── usr
    ├── include -> ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include
    └── lib
        ├── aarch64-linux-android -> ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android
        ├── arm-linux-androideabi -> ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/arm-linux-androideabi
        ├── x86_64-linux-android -> ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/x86_64-linux-android
        ├── swift
        │   └── android
        │       ├── aarch64
        │       │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-aarch64/android/aarch64/swiftrt.o
        │       ├── armv7
        │       │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-armv7/android/armv7/swiftrt.o
        │       └── x86_64
        │           └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-x86_64/android/x86_64/swiftrt.o
        └── swift_static
            └── android
                ├── aarch64
                │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-aarch64/android/aarch64/swiftrt.o
                ├── armv7
                │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-armv7/android/armv7/swiftrt.o
                └── x86_64
                    └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-x86_64/android/x86_64/swiftrt.o

Alternative NDK locations can be specified by overriding the ANDROID_NDK_HOME, like so:

zap org.swift.swiftpm/swift-sdks % ANDROID_NDK_HOME="/opt/homebrew/share/android-ndk" swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-07-a-android-0.1.artifactbundle/swift-android/scripts/setup-android-sdk.sh
setup-android-sdk.sh: success: ndk-sysroot linked to Android SDK

zap org.swift.swiftpm/swift-sdks % tree swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-07-a-android-0.1.artifactbundle/swift-android/ndk-sysroot
└── usr
    ├── include -> /opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include
    └── lib
        ├── aarch64-linux-android -> /opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android
        ├── arm-linux-androideabi -> /opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/arm-linux-androideabi
        ├── x86_64-linux-android -> /opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/x86_64-linux-android
        ├── swift
        │   └── android
        │       ├── aarch64
        │       │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-aarch64/android/aarch64/swiftrt.o
        │       ├── armv7
        │       │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-armv7/android/armv7/swiftrt.o
        │       └── x86_64
        │           └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift-x86_64/android/x86_64/swiftrt.o
        └── swift_static
            └── android
                ├── aarch64
                │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-aarch64/android/aarch64/swiftrt.o
                ├── armv7
                │   └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-armv7/android/armv7/swiftrt.o
                └── x86_64
                    └── swiftrt.o -> ../../../../../../swift-resources/usr/lib/swift_static-x86_64/android/x86_64/swiftrt.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant